
#include "SoundMath.h"

using namespace SoundMath;

double SoundMath::POWNOTE_TABLE[POWNOTE_TABLE_LENGTH];
int dummy = POWNOTE_TABLE_CONSTRUCTOR();

int SoundMath::POWNOTE_TABLE_CONSTRUCTOR()
{
	for (int i = 0; i < POWNOTE_TABLE_LENGTH; i++)
	{
		POWNOTE_TABLE[i] = pow(PowNote, i);
	}
	return 0;
}

double SoundMath::Pow_Note(const double& b)
{
	int int_b = (int)b;
	double dec = b - int_b;
	if (b <= 0)
	{
		return POWNOTE_TABLE[0];
	}
	else if (dec == 0.0)
	{
		return POWNOTE_TABLE[int_b];
	}
	else if (int_b <= POWNOTE_TABLE_LENGTH)
	{
		const double& x1 = POWNOTE_TABLE[int_b];
		return x1 + (POWNOTE_TABLE[int_b + 1] - x1) * dec;
	}
	else
	{
		return pow(PowNote, b);
	}
}